package com.jiangchuang.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jiangchuang.domain.entity.DishType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author jmk
 * @date 2022-12-12 21:08
 */
public interface DishTypeMapper extends BaseMapper<DishType> {

    @Select("select * from dish_type where uid=0 or uid=#{uid} order by seq")
    List<DishType> getUserDishType(Integer uid);

//    @Select("select id,uid,name,cover,num,price,seq from dish where type_id=#{tid} order by seq, create_time")
//    List<Dish> getDishByType(Integer tid);

    /**
     * 从上往下移
     * @return
     */
    @Update("update dish_type set seq=seq-1 where seq>#{oldSeq} and seq<=#{newSeq} and uid=#{uid}")
    Integer sortDown(Integer oldSeq, Integer newSeq, Integer uid);

    /**
     * 从下往上移
     * @return
     */
    @Update("update dish_type set seq=seq+1 where seq>=#{newSeq} and seq<#{oldSeq} and uid=#{uid}")
    Integer sortUp(Integer oldSeq, Integer newSeq, Integer uid);

    /**
     * 获取用户类别中最大的排序
     * @param uid
     * @return
     */
    @Select("select Max(seq) from dish_type where uid=#{uid}")
    Integer getMaxSeq(Integer uid);

    /**
     * 获取某类别中最大的菜品序号
     * @param tid
     * @return
     */
    @Select("select Max(seq) from dish where type_id=#{tid}")
    Integer getMaxDishSeq(Integer tid);

}
